#pragma once
#include<iostream>
#include<string>
#include<fstream>
#include<boost/algorithm/string.hpp>
#include"cppjieba/Jieba.hpp"
#include"log.hpp"


namespace util
{
    class FileUtil
    {
    public:
        static bool ReafFile(const std::string file_path,std::string* raw_file)
        {
            std::ifstream in(file_path,std::ios::in);
            if(!in.is_open())
            {
                //std::cout<<"open file error"<<std::endl;
                LOG(WARNING,"打开文件失败");
                return false;
            }
            std::string line; 
            while(std::getline(in,line))
            {
                (*raw_file)+=line;
                
            }
            in.close();
            return true;
        }
    };
    class StringUtil
    {
    public:
        static void SplitString(std::vector<std::string>* intent,const std::string line,const std::string& sep)
        {
            boost::split(*intent,line,boost::algorithm::is_any_of(sep));
        }
    };

    const char *const DICT_PATH = "./dict/jieba.dict.utf8";
    const char *const HMM_PATH = "./dict/hmm_model.utf8";
    const char *const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char *const IDF_PATH = "./dict/idf.utf8";
    const char *const STOP_WORD_PATH = "./dict/stop_words.utf8";
    class JiebaUtil
    {
    private:
        static cppjieba::Jieba jieba;

    public:
        static void CutString(const std::string &content, std::vector<std::string> *words)
        {
            //std::cout << "content:" << content << std::endl;
            //std::cout << "[demo] CutForSearch" << std::endl;
            jieba.CutForSearch(content, *words);
            //std::cout << limonp::Join(words->begin(), words->end(), "/") << std::endl;
        }
    };
    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH,
                                     HMM_PATH,
                                     USER_DICT_PATH,
                                     IDF_PATH,
                                     STOP_WORD_PATH);
}
